package com.itheima.test;

import java.util.Random;

public class arraytest5 {
    public static void main(String[] args) {
        //生成10个1-100随机数存入数组
        //求和
        //求平均
        //统计多少个数比平均数小

        int[] arr = new int[10];//动态数组
        Random r = new Random();

        for (int i = 0; i < arr.length; i++) {
            int number = r.nextInt(100)+1;//1-100
            arr[i] = number;
        }

        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

        //1.求和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        System.out.println("sum="+sum);

        //2.求平均
        int avg = sum/arr.length;
        System.out.println("avg="+avg);

        //3.统计多少个数比平均数小
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]<avg){
                count++;
            }
        }
        System.out.println("比平均数小的数有"+count+"个");
    }
}
